package mo.tags.greedy;

import java.util.*;

public class L954 {

    public boolean canReorderDoubled(int[] arr) {
        Map<Integer, Integer> cnt = new HashMap<>();
        for (int e : arr) {
            cnt.put(e, cnt.getOrDefault(e, 0)+1);
        }
        int pair = 0;
        Arrays.sort(arr);
        for (int e : arr) {
            if (cnt.getOrDefault(e, 0) == 0) {
                continue;
            }
            if (cnt.getOrDefault(e*2, 0) == 0) {
                continue;
            }
            cnt.put(e, cnt.get(e)-1);
            //只有1个0或1的特殊情况
            if (cnt.getOrDefault(e*2, 0) == 0) {
                return false;
            }
            cnt.put(e*2, cnt.get(e*2)-1);
            pair++;
        }
        return pair == (arr.length / 2);
    }


    public static void main(String[] args) {
        L954 test = new L954();
        System.out.println(test.canReorderDoubled(new int[]{-33, 0}));
    }
}
